package araujoCoronelVillamayor.plantasVsZombies.uiWicket;

import araujoCoronelVillamayor.plantasVsZombies.appModelsArena.JardinZenAppModel;
import araujoCoronelVillamayor.plantasVsZombies.appModelsArena.SesionAppModel;
import araujoCoronelVillamayor.plantasVsZombies.domain.Fila;
import araujoCoronelVillamayor.plantasVsZombies.domain.Jardin;
import araujoCoronelVillamayor.plantasVsZombies.uiWicket.AlmanaquePage;
import araujoCoronelVillamayor.plantasVsZombies.uiWicket.AtaquePage;
import araujoCoronelVillamayor.plantasVsZombies.uiWicket.JardinZenPage;
import araujoCoronelVillamayor.plantasVsZombies.uiWicket.PlantacionPage;
import araujoCoronelVillamayor.plantasVsZombies.uiWicket.layouts.LayoutPrincipal;
import java.util.ArrayList;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.model.CompoundPropertyModel;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function0;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure0;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.uqbar.wicket.xtend.WicketExtensionFactoryMethods;
import org.uqbar.wicket.xtend.XLink;
import org.uqbar.wicket.xtend.XListView;

/**
 * Homepage
 */
@SuppressWarnings("all")
public class JardinPage extends LayoutPrincipal {
  @Extension
  private WicketExtensionFactoryMethods _wicketExtensionFactoryMethods = new Function0<WicketExtensionFactoryMethods>() {
    public WicketExtensionFactoryMethods apply() {
      WicketExtensionFactoryMethods _wicketExtensionFactoryMethods = new WicketExtensionFactoryMethods();
      return _wicketExtensionFactoryMethods;
    }
  }.apply();
  
  public JardinPage() {
    super();
    SesionAppModel _sesionAppModel = new SesionAppModel();
    CompoundPropertyModel<SesionAppModel> _compoundPropertyModel = new CompoundPropertyModel<SesionAppModel>(_sesionAppModel);
    this.setDefaultModel(_compoundPropertyModel);
    Label _label = new Label("nombreJugador");
    this._wicketExtensionFactoryMethods.addChild(this, _label);
    Label _label_1 = new Label("recursos");
    this._wicketExtensionFactoryMethods.addChild(this, _label_1);
    XLink<Object> _xLink = new XLink<Object>("almanaqueZombie");
    final Procedure1<XLink<Object>> _function = new Procedure1<XLink<Object>>() {
      public void apply(final XLink<Object> it) {
        final Procedure0 _function = new Procedure0() {
          public void apply() {
            AlmanaquePage _almanaquePage = new AlmanaquePage(JardinPage.this);
            it.setResponsePage(_almanaquePage);
          }
        };
        it.setOnClick(_function);
      }
    };
    XLink<Object> _doubleArrow = ObjectExtensions.<XLink<Object>>operator_doubleArrow(_xLink, _function);
    this._wicketExtensionFactoryMethods.addChild(this, _doubleArrow);
    XLink<Object> _xLink_1 = new XLink<Object>("jardinZen");
    final Procedure1<XLink<Object>> _function_1 = new Procedure1<XLink<Object>>() {
      public void apply(final XLink<Object> it) {
        final Procedure0 _function = new Procedure0() {
          public void apply() {
            SesionAppModel _sesion = JardinPage.this.getSesion();
            JardinZenAppModel _jardinZenAppModel = _sesion.getJardinZenAppModel();
            JardinPage.this.irJardinZen(_jardinZenAppModel);
          }
        };
        it.setOnClick(_function);
      }
    };
    XLink<Object> _doubleArrow_1 = ObjectExtensions.<XLink<Object>>operator_doubleArrow(_xLink_1, _function_1);
    this._wicketExtensionFactoryMethods.addChild(this, _doubleArrow_1);
    XListView<Fila> _xListView = new XListView<Fila>("resultados");
    final XListView<Fila> listView = _xListView;
    SesionAppModel _sesion = this.getSesion();
    Jardin _jardin = _sesion.getJardin();
    ArrayList<Fila> _filas = _jardin.getFilas();
    CompoundPropertyModel<ArrayList<Fila>> _asCompoundModel = this._wicketExtensionFactoryMethods.<ArrayList<Fila>>asCompoundModel(_filas);
    listView.setModel(_asCompoundModel);
    final Procedure1<ListItem<Fila>> _function_2 = new Procedure1<ListItem<Fila>>() {
      public void apply(final ListItem<Fila> item) {
        Fila _modelObject = item.getModelObject();
        CompoundPropertyModel<Fila> _asCompoundModel = JardinPage.this._wicketExtensionFactoryMethods.<Fila>asCompoundModel(_modelObject);
        item.setModel(_asCompoundModel);
        Label _label = new Label("tipo");
        JardinPage.this._wicketExtensionFactoryMethods.addChild(item, _label);
        Label _label_1 = new Label("cantidadPlantas");
        JardinPage.this._wicketExtensionFactoryMethods.addChild(item, _label_1);
        Label _label_2 = new Label("casillerosPlanta");
        JardinPage.this._wicketExtensionFactoryMethods.addChild(item, _label_2);
        XLink<Object> _xLink = new XLink<Object>("plantar");
        final Procedure1<XLink<Object>> _function = new Procedure1<XLink<Object>>() {
          public void apply(final XLink<Object> it) {
            final Procedure0 _function = new Procedure0() {
              public void apply() {
                Fila _modelObject = item.getModelObject();
                JardinPage.this.irPlantarPage(_modelObject);
              }
            };
            it.setOnClick(_function);
          }
        };
        XLink<Object> _doubleArrow = ObjectExtensions.<XLink<Object>>operator_doubleArrow(_xLink, _function);
        JardinPage.this._wicketExtensionFactoryMethods.addChild(item, _doubleArrow);
        XLink<Object> _xLink_1 = new XLink<Object>("atacar");
        final Procedure1<XLink<Object>> _function_1 = new Procedure1<XLink<Object>>() {
          public void apply(final XLink<Object> it) {
            final Procedure0 _function = new Procedure0() {
              public void apply() {
                Fila _modelObject = item.getModelObject();
                JardinPage.this.atacar(_modelObject);
              }
            };
            it.setOnClick(_function);
          }
        };
        XLink<Object> _doubleArrow_1 = ObjectExtensions.<XLink<Object>>operator_doubleArrow(_xLink_1, _function_1);
        JardinPage.this._wicketExtensionFactoryMethods.addChild(item, _doubleArrow_1);
      }
    };
    listView.setPopulateItem(_function_2);
    this._wicketExtensionFactoryMethods.addChild(this, listView);
  }
  
  public void irPlantarPage(final Fila filaParametro) {
    SesionAppModel _sesion = this.getSesion();
    PlantacionPage _plantacionPage = new PlantacionPage(filaParametro, _sesion, this);
    this.setResponsePage(_plantacionPage);
  }
  
  public void irJardinZen(final JardinZenAppModel jardinZenAppModelparametro) {
    JardinZenPage _jardinZenPage = new JardinZenPage(jardinZenAppModelparametro, this);
    this.setResponsePage(_jardinZenPage);
  }
  
  public void atacar(final Fila filaParametro) {
    SesionAppModel _sesion = this.getSesion();
    AtaquePage _ataquePage = new AtaquePage(filaParametro, _sesion, this);
    this.setResponsePage(_ataquePage);
  }
  
  public SesionAppModel getSesion() {
    Object _defaultModelObject = this.getDefaultModelObject();
    return ((SesionAppModel) _defaultModelObject);
  }
  
  public void refreshFilas() {
    SesionAppModel _sesion = this.getSesion();
    _sesion.refresh();
  }
}
